package ru.spbu.math.seabattle.entity;

import java.util.HashMap;
import java.util.Map;

public class BijectiveHashMap<K, V> {

	private Map<K, V> key2value = new HashMap<K, V>();
	private Map<V, K> value2key = new HashMap<V, K>();
	
	public void put(K key, V value) {
		
		key2value.remove(key);
		value2key.remove(value);
		
		key2value.put(key, value);
		value2key.put(value, key);
	}
	
	public V getByKey(K key) {
		
		return key2value.get(key);
	}
	
	public K getByValue(V value) {
		
		return value2key.get(value);
	}
	
	public void removeByKey(K key) {
		
		V value = key2value.get(key);
		key2value.remove(key);
		value2key.remove(value);
	}
	
	public void removeByValue(V value) {
		
		K key = value2key.get(value);
		key2value.remove(key);
		value2key.remove(value);
	}
}
